﻿$(document).ready(function () {

    //delete, collap & expand function

    $(".delete").click(function(){
        var type = this.rev;
        var confirmQuestion = "Are you sure you want to remove this "+ type +"?";
        if(type=="transsys program"){
            confirmQuestion = confirmQuestion + " All of transsys program definition and its instances will be removed."
        }
        if(confirm(confirmQuestion)){
            //Do delete here
            var curl = $(location).attr('href');
            var delURL = this.id;
            var liTag = $(this).parent().parent();
            var ulTag = liTag.parent();
            $.get(
                delURL,
                {},
                function(data){
                    if (data.status == "success"){
                        $("#messages").html("<li class=\"success\">"+ data.msg +"<\li>");
                        liTag.remove();
                        if (ulTag.children("li").length == 0){
                            ulTag.parent().append("<p>No "+ type +"</p>");
                            ulTag.remove();
                        }
                    } else {
                        $("#messages").html("<li class=\"error\">"+ data.msg +"<\li>");
                    }
                },
                "json"
                );
        } else {
    //Do nothing
    }
    });

    $(".expanded").hide();
    $(".collap").hide();
    
    $(".active").find(".expanded").show();
    $(".active").find(".collap").show();
    $(".active").find(".expand").hide();

    $(".active").find(".list-lv2").find(".expanded").hide();
    $(".active").find(".list-lv2").find(".collap").hide();
    $(".active").find(".list-lv2").find(".expand").show();

    $(".expand").click(function()
    {
        $(this).hide();
        $(this).parent().next(".expanded").toggle();
        $(this).parent().find(".collap").toggle();
        updateHeight();
        
    });

    $(".collap").click(function()
    {
        $(this).hide();
        $(this).parent().next(".expanded").hide();
        $(this).parent().find(".expand").toggle();
        updateHeight();
    });
    

    function updateHeight() {
        $("#right-column").height("auto");
        //$("#right-column").removeClass("right-column");
        //$("#right-column").removeClass("right-column-trick");
        var right_column_height = $("#right-column").height();
        var left_column_height = $("#left-column .inner").height();
        
        var content_column_height = $("#content-body").height();
        //alert(left_column_height);
        //alert(content_column_height);
        //alert(right_column_height);
        if(left_column_height>content_column_height){
            //$("#right-column").addClass("right-column-trick");
            //$("#right-column").height(left_column_height + 100);
            $("#content-body").height(left_column_height);
        } else {
            $("#right-column").addClass("right-column");
        }
    };

    $("#import").click( function(event){
        var confirmQuestion = "All transsys programs and simgenex programs will be replaced by importing workspace. Do you want to continue?";
        if(confirm(confirmQuestion)){
            //Let go
        } else {
            event.preventDefault();
        }
    });
    updateHeight();
});
